﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class AddProductionreturnCommandHanders : IRequestHandler<AddProductionreturnCommands, APIResult<Productionreturn>>
    {
        private readonly IBaseRepository<Productionreturn> baseRepository;
        private readonly IMapper mapper;

        public AddProductionreturnCommandHanders(IBaseRepository<Productionreturn> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加生产退料信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Productionreturn>> Handle(AddProductionreturnCommands request, CancellationToken cancellationToken)
        {
            APIResult<Productionreturn> result = new APIResult<Productionreturn>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";
            var map = mapper.Map<Productionreturn>(request);
            var sql = "insert into Productionreturn values (@PId,@ReturnNumber,@ReturnName,@Returntype,@Productionwork,@Workstation,@ReturnTime,@DocumentStatus,@Remark,@IsDelete)";
            await baseRepository.Insert(map, sql);
            return result;
        }
    }
}
